/**
 * Created by zhangligang
 * Email: tzhang2450@163.com
 * Date: 2019/1/19
 * Time: 23:41
 */
$(function () {
    var url = '/v1/manager/department/increase/score.json';

    var toolbar = '';

    loadList(url, toolbar);

    $(document).on({
        change: function () {
            refreshList();
        }
    },'.select-status');

    $(document).on('click', '.btn-delete', function () {
        deleteData('', $(this).attr('data-id'));
    });

});

function loadList(url, toolbar) {
    $('.data-table').bootstrapTable({
        url: url,
        ajaxOptions:{
            headers: {"Authorization": $.cookie()._token}
        },
        pagination: true,
        toolbar: toolbar,
        iconSize: "outline",
        pageList: [10, 20, 50, 100],
        search: true,
        sortable: false,
        sortOrder: 'desc',
        striped: true,
        sortStable: true,
        sidePagination: 'server',
        queryParams : function (params) {
            params.department_id = department_id;
            params.status = $('.search-key').val();
            return params;
        },
        icons: {
            refresh: "glyphicon-repeat",
            columns: "glyphicon-list"
        },
        columns: [{
            field: 'id',
            title: '序号'
        }, {
            field: 'title',
            title: '文章标题'
        }, {
            field: 'created_at',
            title: '时间'
        }, {
            field: 'score',
            title: '分数'
        }, {
            field: 'id',
            title: '操作',
            formatter: function (value) {
                return '<a class="btn btn-sm btn-info" href="/manager/grade-increase-'+value+'-department-'+department_id+'.html"><i class="fa fa-edit"></i>打分</a>';
            }
        }]
    });
}

function refreshList() {
    $('.data-table').bootstrapTable('refresh');
}